import React from 'react';
import { Modal } from 'antd';
import { formatMessage } from 'umi';
import { TipBox } from '../../../components';
import { acceptTask } from '../../../services';
import styles from './index.less';

export const showAcceptanceYesModal = ({ taskId, onOk }) => {
    // console.log('showAcceptanceYesModal -> taskId', taskId);
    Modal.confirm({
        title: '验收通过',
        content: <TipBox title="确定验收通过？" />,
        className: styles.confirmModal,
        okText: formatMessage({ id: 'btn.form.confirm' }),
        cancelText: formatMessage({ id: 'btn.form.cancel' }),
        onOk: () =>
            new Promise((resolve, reject) => {
                acceptTask({
                    taskId,
                    acceptStatus: 1
                })
                    .then(res => {
                        const { code } = res;
                        if (code === 10000) {
                            if (onOk) onOk();
                            resolve();
                        } else {
                            reject();
                        }
                    })
                    .catch(() => {
                        reject();
                    });
            })
    });
};
